//
//  LBCYThreeLevelShowViewController.m
//  AFNetworking
//
//  Created by luckyRoy on 2018/3/14.
//

#import "LBCYThreeLevelShowViewController.h"
#import <LBCategoryMainView.h>
#import "Masonry.h"

@interface LBCYThreeLevelShowViewController ()

@property (nonatomic, copy) LBCYThreeLevelViewBlock choseBlock;

@property (nonatomic, weak) LBCategorySettingModel *settingModel;

@property (nonatomic, strong) LBCategoryMainView *mainView;

@end

@implementation LBCYThreeLevelShowViewController

- (void)updateBySettingModel:(LBCategorySettingModel *)settingModel
                  choseBlock:(LBCYThreeLevelViewBlock)choseBlock
{
    self.settingModel = settingModel;
    self.choseBlock = choseBlock;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"选择分类";
    [self.view addSubview:self.mainView];
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    [self reloadListView];
}

- (void)reloadListView
{
    [self.mainView reloadViewByNewListModels:[LBCategorySettingModel getListModelBySettingModel:self.settingModel currentPage:LBCategorySettingPageTypeThreeLevel]];
}

#pragma mark - life cycle

#pragma mark - setUpFrame

#pragma mark - public

#pragma mark - private

#pragma mark - request

#pragma mark - setter

#pragma mark - getter

- (LBCategoryMainView *)mainView
{
    if (!_mainView) {
        __weak __typeof(&*self)weakSelf = self;
        LBCategoryMainViewLayout *viewLayout = [LBCategoryMainViewLayout new];
        viewLayout.isShowSearchView = YES;
        viewLayout.pageType = LBCategorySettingPageTypeThreeLevel;
        if (!self.settingModel.isSingleSelected) {
            viewLayout.isShowConfirmView = YES;
        }
        _mainView = [[LBCategoryMainView alloc]initWithFrame:self.view.bounds settingModel:self.settingModel viewLayout:viewLayout complete:^(LBCategoryMainViewLayout *blockModel,NSMutableArray *selectedArry) {
            
            if (weakSelf.choseBlock) {
                weakSelf.choseBlock(selectedArry);
            }
            
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }];
    }
    return _mainView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
